# Definition for a binary tree node.
class TreeNode(object):
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None

    def createTestTree(self,root):
        if root!= None:
            root.val = 4
            root.left = TreeNode(2)
            root.left.left= TreeNode(1)
            root.left.right = TreeNode(3)
            root.right = TreeNode(7)
            root.right.left= TreeNode(6)
            root.right.right = TreeNode(9)

class Solution(object):
    def invertTree(self, root):
        """
        :type root: TreeNode
        :rtype: TreeNode
        """
        if root!=None:
            if root.left!=None:
                self.invertTree(root.left)
            if root.right!=None:
                self.invertTree(root.right)
            if root.left!=None and root.right != None:
                root.left,root.right = root.right,root.left

test_tree =None
a = Solution()
b = TreeNode(0)
b.createTestTree(b)
# c = TreeNode.createTestTree()
c = b
a.invertTree(c)
print (b)

# TreeNode.createTestTree(test_tree)

